﻿using Common.Contract;
using Common.Contract.Customer.Identifier;
using Common.Contract.Customer.Record;
using Common.Contract.DataCenter.Record;
using Common.Contract.DataCenter.Request;
using Common.Contract.SaleOut.Record;
using Common.Contract.Warranty.Record;
using Common.Service.Command;
using Common.Service.Queue;
using Common.Util;
using DataCenter.Configuration;
using DataCenter.Model.Interface;
using DataCenter.Model.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataCenter.ServiceCommand
{
    public class UpdateResponseSMSServiceCommand : ProviderQueueCommand<IProviderFactory, ResponseSMSRecord, ResponseRecord>
    {
        public UpdateResponseSMSServiceCommand(IProviderFactory provider) : base(provider) { }
        protected override void Validate(ResponseSMSRecord record)
        {
            if (record == null) throw new ArgumentNullException("request");
        }

        protected override bool OnExecute(ResponseRecord response)
        {
            var record = Record;
            var obj = new ResponseSMS()
            {
                CreateDate = DateTime.Now,
                GabitId = record.GabitId,
                GabitTemplate = record.GabitTemplate,
                MsgBodyLen = record.MsgBodyLen,
                Purpose = record.Purpose,
                RespMsg1 = record.RespMsg1,
                RespMsg2 = record.RespMsg2,
                RespType = record.RespType,
                Template = record.Template,
                SoTransferDate = DateTime.Now,
                SoTransferFlag = BooleanString.TRUE,
            };
            var itemCheck = Providers.ResponseSMS.RetrieveResponseSMS(record.RespType);
            if (itemCheck == null)
            {
                var resultitem1 = Providers.ResponseSMS.Add(obj);
            }
            else
            {
                var resultitem2 = Providers.ResponseSMS.Update(obj);
            }
            return true;
        }
    }
}
